package com.spring.demo.springdemo.config;

import org.springframework.context.ApplicationEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.context.PayloadApplicationEvent;
import org.springframework.stereotype.Component;

/**
 * @Author RenPu
 * @Date 2024/2/17 16:24
 * @Version 1.0
 * @Description: Spring得事件《监听机制》得定义
 **/
//@Component
public class ProgcessEventListerner implements ApplicationListener {


    @Override
    public void onApplicationEvent(ApplicationEvent event) {

        //当发布的对象，没有实现ApplicationEvent，则默认转化为PayloadApplicationEvent对象
        PayloadApplicationEvent payloadApplicationEvent=(PayloadApplicationEvent)event;

        System.out.println("接收发布得事件内容为：：：：：："+payloadApplicationEvent.getPayload());
    }

    //通过注解得形式，实现事件监听得实现，存在得类必须为Bean才可以生效，例如在类上被@Compoent修饰得
    //    @EventListener
//    public void listerner(){
//
//
//    }
}
